optimized fishing when looking up existing fish (should perhaps be moved
authorØyvind Kolås <ok@src.gnome.org>
Tue, 13 Nov 2007 00:05:46 +0000 (00:05 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Tue, 13 Nov 2007 00:05:46 +0000 (00:05 +0000)
* babl/babl-fish.c: (go_fishing): optimized fishing when looking
up existing fish (should perhaps be moved to lists going from given
formats, similar to how conversions are added there instead.) Made
go_fishing accept BABL_FISH_REFERENCE when source and desintation
formats are equal.
(babl_fish_process): removed most of the need for BablImage for
linear buffers, do a memcpy when source and destination formats
are equal (and we're a BABL_FISH_REFERENCE).
* babl/babl-db.[ch]: moved the BablDb struct out into public to
allow faster iteration through it.

svn path=/trunk/; revision=250

ChangeLog
babl/babl-db.c
babl/babl-db.h
babl/babl-fish.c

index 9c34314857d88941d267308ea91b91a1aad5d7f5..fae4f2b4a57f4f8fd5c62c25a6eefba8748c062a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2007-11-13  Øyvind Kolås  <pippin@gimp.org>
+
+       * babl/babl-fish.c: (go_fishing): optimized fishing when looking
+       up existing fish (should perhaps be moved to lists going from given
+       formats, similar to how conversions are added there instead.) Made
+       go_fishing accept BABL_FISH_REFERENCE when source and desintation
+       formats are equal.
+         (babl_fish_process): removed most of the need for BablImage for
+         linear buffers, do a memcpy when source and destination formats
+         are equal (and we're a BABL_FISH_REFERENCE).
+       * babl/babl-db.[ch]: moved the BablDb struct out into public to
+       allow faster iteration through it.
+
 2007-11-11  Øyvind Kolås  <pippin@gimp.org>
 
        * Modified copyright statement to refer to an URL instead of a civic
index 3de4e9e784777ac3325444035fbafd136fae50b4..266f8d5b4b6eb4beb25906208fda22da2a791f1d 100644 (file)
@@ -21,7 +21,6 @@
 #include <string.h>
 #include "babl-internal.h"
 
-#define HASH_TABLE_SIZE      128
 #define DB_INITIAL_SIZE      16
 #define DB_INCREMENT_SIZE    16
 
@@ -35,13 +34,6 @@ static inline int hash (const char *str)
   return ret;
 }
 
-typedef struct _BablDb
-{
-  Babl  *hash [HASH_TABLE_SIZE];
-  int    size;
-  int    count;
-  Babl **items;
-} _BablDb;
 
 Babl *
 babl_db_find (BablDb     *db,
index dfb59115576826b381decee52418cf2f0485da72..9c49a3d48b4dcbf5822bd4512db26ac412ab604c 100644 (file)
 
 typedef struct _BablDb BablDb;
 
+#define HASH_TABLE_SIZE      128
+typedef struct _BablDb
+{
+  Babl  *hash [HASH_TABLE_SIZE];
+  int    size;
+  int    count;
+  Babl **items;
+} _BablDb;
+
 BablDb * babl_db_init    (void);
 void     babl_db_destroy (BablDb           *db);
 void     babl_db_each    (BablDb           *db, 
index ac9cb789705703e900049d977f090ffacaedd0a3..1aa329efc69b4be1cac69eec45658fe49dcd8a8d 100644 (file)
@@ -55,48 +55,26 @@ babl_fish_db (void)
   return db;
 }
 
-typedef struct BablFishingData
-{
-  Babl *source;
-  Babl *destination;
-  Babl *ret;
-} BablFishingData;
-
-static int
-fishing_result_examine (Babl *babl,
-                        void *void_data)
-{
-  BablFishingData *data = void_data;
-
-  if ((void *) data->source == (void *) babl->fish.source &&
-      (void *) data->destination == (void *) babl->fish.destination)
-    {
-      data->ret = babl;
-      /* we do not return BABL_FISH_REFERENCE's since those might exist
-       * even before a valid BABL_FISH_PATH has been constructed for a
-       * given conversion.
-       */
-      if (data->ret->class_type == BABL_FISH_REFERENCE)
-        return 0;
-      return 1;     /* stop iterating */
-    }
-  return 0;  /* continue iterating */
-}
-
-static Babl *
+static inline Babl *
 go_fishing (Babl *source,
             Babl *destination)
 {
-  {
-    BablFishingData data;
+  BablDb *db = babl_fish_db ();
+  int i;
 
-    data.source      = source;
-    data.destination = destination;
-    data.ret         = NULL;
-
-    babl_db_each (db, fishing_result_examine, &data);
-    return data.ret;
-  }
+  for (i=0; i<db->count; i++)
+    {
+      Babl *item = db->items[i];
+      if ((void *) source == (void *) item->fish.source &&
+          (void *) destination == (void *) item->fish.destination &&
+          (item->class_type != BABL_FISH_REFERENCE ||
+           source == destination)
+          )
+        {
+          return item;
+        }
+    }
+  return NULL;
 }
 
 Babl *
@@ -142,7 +120,7 @@ babl_fish (void *source,
       return NULL;
     }
 
-  if(1){
+  {
     Babl *lucky;
     lucky = go_fishing (source_format, destination_format);
     if (lucky)
@@ -184,8 +162,6 @@ babl_fish_process (Babl *babl,
                    void *destination,
                    long  n)
 {
-  BablImage *source_image      = NULL;
-  BablImage *destination_image = NULL;
   long       ret               = 0;
 
   switch (babl->class_type)
@@ -193,25 +169,17 @@ babl_fish_process (Babl *babl,
       case BABL_FISH_REFERENCE:
       case BABL_FISH_SIMPLE:
       case BABL_FISH_PATH:
-
-#if 0
-        if (BABL_IS_BABL (source))
-          source_image = source;
-#endif
-        if (!source_image)
-          source_image = (BablImage *) babl_image_from_linear (
-            source, (Babl *) babl->fish.source);
-#if 0
-        if (BABL_IS_BABL (destination))
-          destination_image = destination;
-#endif
-        if (!destination_image)
-          destination_image = (BablImage *) babl_image_from_linear (
-            destination, (Babl *) babl->fish.destination);
-
         if (babl->class_type == BABL_FISH_REFERENCE)
           {
-            ret = babl_fish_reference_process (babl, source, destination, n);
+            if (babl->fish.source == babl->fish.destination)
+              { /* XXX: we're assuming linear buffers */
+                memcpy (source, destination, n * babl->fish.source->format.bytes_per_pixel);
+                ret = n;
+              }
+            else
+              {
+                ret = babl_fish_reference_process (babl, source, destination, n);
+              }
           }
         else if (babl->class_type == BABL_FISH_PATH)
           {
@@ -226,15 +194,10 @@ babl_fish_process (Babl *babl,
               }
             else
               {
-                ret = babl_conversion_process (BABL (babl->fish_simple.conversion),
-                                               (char *) source_image, (char *) destination_image, n);
+                babl_assert (0);
               }
           }
-
-        babl_free (source_image);
-        babl_free (destination_image);
         break;
-
       default:
         babl_log ("NYI");
         ret = -1;